package command
{
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import flash.net.URLRequestMethod;
	
	import model.ApplicationModel;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.mxml.HTTPService;
	import vo.Level;
	
	public class AuthenticateUserCommand extends BaseCommand
	{
		private var _model:ApplicationModel=ApplicationModel.instance;
		public override function doExecute(event:CairngormEvent):void
		{
			// Test parametros 
			var params:Object = new Object();
			var httpService:HTTPService = new HTTPService();
			httpService.url= _model.URL_AUTHENTICATE_USER;
			httpService.useProxy = false;
			httpService.addEventListener(ResultEvent.RESULT,onResult);
			httpService.addEventListener(FaultEvent.FAULT, onFault);
			httpService.method = URLRequestMethod.POST;
			httpService.send(params);
          	
		}

		public function onResult(data:Object):void
		{
			var resultObj:Object = data.result;
			_model.userID = resultObj.data.userID;
		}	
		
		public function onFault(data:Object):void
		{
			Alert.show("Problema al realizar la autentificacion con Facebook","Fail");
		}

	}
}